/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from 'react';
import {Renderer, normalizeLink, filter, render} from '../renderer';
import * as cx from 'classnames';
import {Link} from 'react-router';
import * as schema from './nav-schema.json';
import './item';

@Renderer({
  name: 'nav',
  desc: '...',
  test: (path, config) => /(?:^|\/)nav$/.test(path),
  schema
})
export default class Navigation extends Component {
  static propTypes = {
    className: PropTypes.string,
    location: PropTypes.object.isRequired,
    links: PropTypes.arrayOf(PropTypes.shape({
      to: PropTypes.string.isRequired
    })),
    overrideParams: PropTypes.bool.isRequired
  };

  static defaultProps = {
    className: '',
    overrideParams: false,
    stacked: true
  };

  render() {
    const {
      className,
      links,
      placeholder,
      location,
      overrideParams,
      stacked,
      data,
      $path
    } = this.props;

    if (!links || !links.length) {
      return (<p className="text-muted">{placeholder}</p>);
    }

    return (
      <ul
        className={cx('nav', className, stacked ? 'nav-pills nav-stacked' : 'nav-tabs')}
      >
        {links.map((link, key) => render(`${$path}/item`, link, {
          key,
          data,
          location
        }))}
      </ul>
    );
  }
}
